namespace BXS.API.Models
{
    /// <summary>
    /// 统一API响应格式
    /// </summary>
    /// <typeparam name="T">响应数据类型</typeparam>
    public class ApiResponse<T>
    {
        /// <summary>
        /// 状态码
        /// </summary>
        public int Code { get; set; }

        /// <summary>
        /// 响应消息
        /// </summary>
        public string Message { get; set; } = string.Empty;

        /// <summary>
        /// 响应数据
        /// </summary>
        public T? Data { get; set; }

        /// <summary>
        /// 是否成功
        /// </summary>
        public bool IsSuccess { get; set; }

        /// <summary>
        /// 时间戳
        /// </summary>
        public long Timestamp { get; set; } = DateTimeOffset.UtcNow.ToUnixTimeSeconds();

        /// <summary>
        /// 创建成功响应
        /// </summary>
        /// <param name="data">响应数据</param>
        /// <param name="message">响应消息</param>
        /// <returns>成功响应</returns>
        public static ApiResponse<T> Success(T data, string message = "成功")
        {
            return new ApiResponse<T>
            {
                Code = 200,
                Message = message,
                Data = data,
                IsSuccess = true
            };
        }

        /// <summary>
        /// 创建错误响应
        /// </summary>
        /// <param name="message">错误消息</param>
        /// <param name="code">错误码</param>
        /// <returns>错误响应</returns>
        public static ApiResponse<T> Error(string message, int code = 500)
        {
            return new ApiResponse<T>
            {
                Code = code,
                Message = message,
                Data = default,
                IsSuccess = false
            };
        }
    }

    /// <summary>
    /// 分页响应格式
    /// </summary>
    /// <typeparam name="T">数据类型</typeparam>
    public class PagedApiResponse<T> : ApiResponse<List<T>>
    {
        /// <summary>
        /// 总记录数
        /// </summary>
        public int Total { get; set; }

        /// <summary>
        /// 当前页码
        /// </summary>
        public int Page { get; set; }

        /// <summary>
        /// 每页大小
        /// </summary>
        public int PageSize { get; set; }

        /// <summary>
        /// 总页数
        /// </summary>
        public int TotalPages { get; set; }

        /// <summary>
        /// 创建分页成功响应
        /// </summary>
        /// <param name="data">数据列表</param>
        /// <param name="total">总记录数</param>
        /// <param name="page">当前页码</param>
        /// <param name="pageSize">每页大小</param>
        /// <param name="message">响应消息</param>
        /// <returns>分页响应</returns>
        public static PagedApiResponse<T> Success(List<T> data, int total, int page, int pageSize, string message = "成功")
        {
            return new PagedApiResponse<T>
            {
                Code = 200,
                Message = message,
                Data = data,
                IsSuccess = true,
                Total = total,
                Page = page,
                PageSize = pageSize,
                TotalPages = (int)Math.Ceiling((double)total / pageSize)
            };
        }
    }
} 